package com.carvajal.adminpos.models.actions;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.carvajal.adminpos.helpers.AdminPOSDbHelper;
import com.carvajal.adminpos.models.User;
import com.carvajal.adminpos.models.User.UserEntry;

public class UserAction {
	
	private static final String TAG = UserAction.class.getSimpleName();
	private Context context;
	
	
	public UserAction(Context context) {
		this.context = context;
	}
	
	public void createUser(User user) {
		Log.i(TAG, "createUser");
		SQLiteDatabase db = null;
		try {
			AdminPOSDbHelper mDbHelper  = new AdminPOSDbHelper(context);
			db = mDbHelper.getReadableDatabase();
			
			// Create a new map of values, where column names are the keys
			ContentValues values = new ContentValues();
			values.put(UserEntry.COLUMN_NAME_USER_NAME, user.getUsername());
			values.put(UserEntry.COLUMN_NAME_PASSWORK, user.getPassword());
			
			//db.insertWithOnConflict(UserEntry.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);
			db.insert(UserEntry.TABLE_NAME, null, values);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (db != null) {
				db.close();
			}
		}
	}

}
